//
//  ZDTabBarButton.m
//  TabBar控制器
//
//  Created by 跑腿仔 on 15/12/19.
//  Copyright © 2015年 paotuizai. All rights reserved.
//

#import "ZDTabBarButton.h"
#import "UIKit+AFNetworking.h"

@implementation ZDTabBarButton

//自定义的Button
+(ZDTabBarButton *)tabBarButtonWithTitle:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    ZDTabBarButton * btn = [ZDTabBarButton buttonWithType:UIButtonTypeCustom];
    
    [btn setTitle:title forState:UIControlStateNormal];
//    [btn setImage:image forState:UIControlStateNormal];
    [btn setImageForState:UIControlStateNormal withURL:[NSURL URLWithString:image]];
    [btn setImageForState:UIControlStateSelected withURL:[NSURL URLWithString:selectedImage]];
    
    [btn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor clearColor] forState:UIControlStateSelected];
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    
    return btn;
}

- (void)setHighlighted:(BOOL)highlighted{
    ;
}

//重写button的image的位置
-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat x, y, w, h;
    w = h = contentRect.size.height*0.8;
    y = contentRect.size.height*0.1;
    x = contentRect.size.width/2-w/2;
    
    return CGRectMake(x, y, w, h);
}

//重写button的title的位置
-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    CGFloat x, y, w, h;
    w = contentRect.size.width*0.8;
    h = contentRect.size.height*0.3;
    x = contentRect.size.width*0.1;
    y = contentRect.size.height*0.6;
    
    return CGRectMake(x, y, w, h);
}

@end
